@extends('../manage.layout')
@section('content')
    <script>
        var editor;
        KindEditor.ready(function(K) {
            editor = K.create('textarea[name="content"]', {
                allowFileManager:false,
                width:"100%",
                height:'300px'
            });
        });
    </script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            内容管理
            <small>文章编辑</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
            <li class="active">Here</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box-body table-responsive no-padding">
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <h3 class="box-title">文章更新</h3>
                        </div>
                        <!-- /.box-header -->
                        <!-- form start -->
                        <form method="post" action="{{ url('manage/article/' . $articles->id) }}" enctype="multipart/form-data">
                            {{ csrf_field() }}
                            {{ method_field('PUT') }}
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="">文章分类</label>
                                    <select class="form-control" name="category">
                                        <option value="">请选择</option>
                                        @foreach($categorys as $category)
                                            @if($category->parent == 0)
                                                @if($category->id == $articles->category)
                                                    <option value="{{ $category->id }}" selected>{{ $category->name }}</option>
                                                @else
                                                    <option value="{{ $category->id }}">{{ $category->name }}</option>
                                                @endif
                                                {{ $result = $categorys->where('parent', $category->id) }}
                                                @if(!$result->isEmpty()) {
                                                @foreach($categorys as $son)
                                                    @if($category->id == $son->parent)
                                                        @if($son->id == $articles->category)
                                                            <option value="{{ $son->id }}" selected>&nbsp;&nbsp;&nbsp;&nbsp;⠧{{ $son->name }}</option>
                                                        @else
                                                            <option value="{{ $son->id }}">&nbsp;&nbsp;&nbsp;&nbsp;⠧{{ $son->name }}</option>
                                                        @endif

                                                    @endif
                                                @endforeach
                                                @endif
                                            @endif
                                        @endforeach
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="title">文章标题</label>
                                    <input type="input" class="form-control" id="title" name="title" placeholder="文章名称" value="{{ $articles->title }}" required>
                                </div>
                                <div class="form-group">
                                    <label for="name">作者</label>
                                    <input type="input" class="form-control" id="author" name="author" placeholder="文章作者" value="{{ $articles->author }}">
                                </div>
                                <div class="form-group">
                                    <label for="name">关键字</label>
                                    <input type="input" class="form-control" id="keyword" name="keyword" placeholder="文章关键字" value="{{ $articles->keyword }}">
                                </div>
                                <div class="form-group">
                                    <label for="name">权重</label>
                                    <input type="input" class="form-control" id="rank" name="rank" placeholder="文章关键字" value="{{ $articles->rank }}">
                                </div>
                                <div class="form-group">
                                    <label for="name">状态</label>
                                    <select class="form-control" name="status" id="status">
                                        @if($articles->status == 1)
                                            <option value="1" selected>启用</option>
                                            <option value="0">禁用</option>
                                        @else
                                            <option value="1">启用</option>
                                            <option value="0" selected>禁用</option>
                                        @endif
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="name">描述</label>
                                    <textarea class="form-control" rows="2" placeholder="文章描述" id="description" name="description">{{ $articles->description }}</textarea>
                                </div>
                                <div class="form-group">
                                    <label for="name">导读图</label>
                                    <input type="file" id="file" name="file"><img src="/upload/{{ $articles->file }}" width="100" height="100" />
                                </div>
                                <div class="form-group">
                                    <label for="name">内容</label>
                                    <textarea id="content" name="content">{{ $articles->content }}</textarea>
                                </div>
                            </div>
                            <!-- /.box-body -->

                            <div class="box-footer">
                                <button type="submit" class="btn btn-primary">确定</button>&nbsp;&nbsp;<span class="btn btn-primary" onclick="window.location.href='/manage/article'">返回</span>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
@endsection
@section('script')
@endsection
{{--
<script src="/plugin/jquery/jquery-2.2.1.min.js"></script>
<script src="/plugin/layer-2.4/layer.js"></script>
<script type="text/javascript">
    $(function () {
        $("form").submit(function(event) {
            event.preventDefault();
            var url = $(this).attr('action');
            ajaxToken({
                url: url,
                type: "POST",
                data: $("form").serialize(),
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    layer.msg(data.msg);
                }
            });
        });
    });
</script>
--}}
